/*
//              INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license  agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in  accordance  with the terms of that agreement.
//    Copyright (c) 2003-2008 Intel Corporation. All Rights Reserved.
//
//
*/
#include "umc_defs.h"
#if defined (UMC_ENABLE_DV_VIDEO_DECODER)

#include "umc_dv_decoder.h"
#include <ipps.h>
#include "umc_memory_allocator.h"

namespace UMC
{

enum
{
    ALING_VALUE                 = 16
};

#define SIZE_TABLE_A_DEQUANTIZE  (64 * 14 * sizeof(Ipp16u))

#define INIT_A_D_E(num, zone0, zone1, zone2, zone3) \
    lpBuffer[(num) * 64 + 0] = 1;                   \
    lpBuffer[(num) * 64 + 1] = zone0;/*zone0;*/     \
    lpBuffer[(num) * 64 + 2] = zone0;               \
    lpBuffer[(num) * 64 + 3] = zone0;               \
    lpBuffer[(num) * 64 + 4] = zone0;               \
    lpBuffer[(num) * 64 + 5] = zone0;               \
    lpBuffer[(num) * 64 + 6] = zone1;               \
    lpBuffer[(num) * 64 + 7] = zone1;/*zone1;*/     \
    lpBuffer[(num) * 64 + 8] = zone1;               \
    lpBuffer[(num) * 64 + 9] = zone1;               \
    lpBuffer[(num) * 64 + 10] = zone1;              \
    lpBuffer[(num) * 64 + 11] = zone1;              \
    lpBuffer[(num) * 64 + 12] = zone1;              \
    lpBuffer[(num) * 64 + 13] = zone1;              \
    lpBuffer[(num) * 64 + 14] = zone1;              \
    lpBuffer[(num) * 64 + 15] = zone1;              \
    lpBuffer[(num) * 64 + 16] = zone1;              \
    lpBuffer[(num) * 64 + 17] = zone1;              \
    lpBuffer[(num) * 64 + 18] = zone1;              \
    lpBuffer[(num) * 64 + 19] = zone1;              \
    lpBuffer[(num) * 64 + 20] = zone1;              \
    lpBuffer[(num) * 64 + 21] = zone2;              \
    lpBuffer[(num) * 64 + 22] = zone2;              \
    lpBuffer[(num) * 64 + 23] = zone2;              \
    lpBuffer[(num) * 64 + 24] = zone2;              \
    lpBuffer[(num) * 64 + 25] = zone2;              \
    lpBuffer[(num) * 64 + 26] = zone2;              \
    lpBuffer[(num) * 64 + 27] = zone2;              \
    lpBuffer[(num) * 64 + 28] = zone2;              \
    lpBuffer[(num) * 64 + 29] = zone2;              \
    lpBuffer[(num) * 64 + 30] = zone2;              \
    lpBuffer[(num) * 64 + 31] = zone2;              \
    lpBuffer[(num) * 64 + 32] = zone2;              \
    lpBuffer[(num) * 64 + 33] = zone2;              \
    lpBuffer[(num) * 64 + 34] = zone2;              \
    lpBuffer[(num) * 64 + 35] = zone2;              \
    lpBuffer[(num) * 64 + 36] = zone2;              \
    lpBuffer[(num) * 64 + 37] = zone2;              \
    lpBuffer[(num) * 64 + 38] = zone2;              \
    lpBuffer[(num) * 64 + 39] = zone2;              \
    lpBuffer[(num) * 64 + 40] = zone2;              \
    lpBuffer[(num) * 64 + 41] = zone2;              \
    lpBuffer[(num) * 64 + 42] = zone2;              \
    lpBuffer[(num) * 64 + 43] = zone3;              \
    lpBuffer[(num) * 64 + 44] = zone3;              \
    lpBuffer[(num) * 64 + 45] = zone3;              \
    lpBuffer[(num) * 64 + 46] = zone3;              \
    lpBuffer[(num) * 64 + 47] = zone3;              \
    lpBuffer[(num) * 64 + 48] = zone3;              \
    lpBuffer[(num) * 64 + 49] = zone3;              \
    lpBuffer[(num) * 64 + 50] = zone3;              \
    lpBuffer[(num) * 64 + 51] = zone3;              \
    lpBuffer[(num) * 64 + 52] = zone3;              \
    lpBuffer[(num) * 64 + 53] = zone3;              \
    lpBuffer[(num) * 64 + 54] = zone3;              \
    lpBuffer[(num) * 64 + 55] = zone3;              \
    lpBuffer[(num) * 64 + 56] = zone3;              \
    lpBuffer[(num) * 64 + 57] = zone3;              \
    lpBuffer[(num) * 64 + 58] = zone3;              \
    lpBuffer[(num) * 64 + 59] = zone3;              \
    lpBuffer[(num) * 64 + 60] = zone3;              \
    lpBuffer[(num) * 64 + 61] = zone3;              \
    lpBuffer[(num) * 64 + 62] = zone3;              \
    lpBuffer[(num) * 64 + 63] = zone3;

#define _INTERNAL_CS1 0.980785  //cos(1*PI/16)
#define _INTERNAL_CS2 0.923880  //cos(2*PI/16)
#define _INTERNAL_CS3 0.831470  //cos(3*PI/16)
#define _INTERNAL_CS4 0.707107  //cos(4*PI/16)
#define _INTERNAL_CS5 0.555570  //cos(5*PI/16)
#define _INTERNAL_CS6 0.382683  //cos(6*PI/16)
#define _INTERNAL_CS7 0.195090  //cos(7*PI/16)

#define _W0 (1.0000001)
#define _W1 (_INTERNAL_CS4 / (4.0 * _INTERNAL_CS7 * _INTERNAL_CS2))
#define _W2 (_INTERNAL_CS4 / (2.0 * _INTERNAL_CS6))
#define _W3 (1.0 / (2.0 * _INTERNAL_CS5))
#define _W4 (7.0 / 8.0)
#define _W5 (_INTERNAL_CS4 / _INTERNAL_CS3)
#define _W6 (_INTERNAL_CS4 / _INTERNAL_CS2)
#define _W7 (_INTERNAL_CS4 / _INTERNAL_CS1)

Ipp32s DVVideoDecoder::dvTable1[] =
{
    9, /* Maximum length of code in this table*/
    0, /* Not used */
    0, /* Not used */
    0, /* Number of 1-bit codes */
    0, /* Number of 2-bit codes */
    2, /* Number of 3-bit codes */
    0x0000, 0, 1,       0x0001, 0, -1,
    3, /* Number of  4-bit codes */
    0x0004, 0,  2,      0x0005, 0, -2,

    0x0006, 100, 100,  /* EOB */

    6, /* Number of 5-bit codes */
    0x000e, 1, 1,       0x000f, 1, -1,
    0x0010, 0, 3,       0x0011, 0, -3,
    0x0012, 0, 4,       0x0013, 0, -4,
    8, /* Number of 6-bit codes */
    0x0028, 2, 1,       0x0029, 2, -1,
    0x002a, 1, 2,       0x002b, 1, -2,
    0x002c, 0, 5,       0x002d, 0, -5,
    0x002e, 0, 6,       0x002f, 0, -6,
    8, /* Number of 7-bit codes */
    0x0060, 3, 1,       0x0061, 3, -1,
    0x0062, 4, 1,       0x0063, 4, -1,
    0x0064, 0, 7,       0x0065, 0, -7,
    0x0066, 0, 8,       0x0067, 0, -8,

    16, /* Number of 8-bit codes */
    0x00d0, 5, 1,       0x00d1, 5, -1,
    0x00d2, 6, 1,       0x00d3, 6, -1,
    0x00d4, 2, 2,       0x00d5, 2, -2,
    0x00d6, 1, 3,       0x00d7, 1, -3,
    0x00d8, 1, 4,       0x00d9, 1, -4,
    0x00da, 0, 9,       0x00db, 0, -9,
    0x00dc, 0, 10,      0x00dd, 0, -10,
    0x00de, 0, 11,      0x00df, 0, -11,
    32, /* Number of 9-bit codes */
    0x01c0, 7, 1,       0x01c1, 7, -1,
    0x01c2, 8, 1,       0x01c3, 8, -1,
    0x01c4, 9, 1,       0x01c5, 9, -1,
    0x01c6, 10, 1,      0x01c7, 10, -1,
    0x01c8, 3, 2,       0x01c9, 3, -2,
    0x01ca, 4, 2,       0x01cb, 4, -2,
    0x01cc, 2, 3,       0x01cd, 2, -3,
    0x01ce, 1, 5,       0x01cf, 1, -5,

    0x01d0, 1, 6,       0x01d1, 1, -6,
    0x01d2, 1, 7,       0x01d3, 1, -7,
    0x01d4, 0, 12,      0x01d5, 0, -12,
    0x01d6, 0, 13,      0x01d7, 0, -13,
    0x01d8, 0, 14,      0x01d9, 0, -14,
    0x01da, 0, 15,      0x01db, 0, -15,
    0x01dc, 0, 16,      0x01dd, 0, -16,
    0x01de, 0, 17,      0x01df, 0, -17,
    -1 /* end of table */
};

Ipp32s DVVideoDecoder::dvTable2[] =
{
    9, /* Maximum length of code. Note that 4 is added to
          all code lengths in the second table */
    0, /* Not used */
    0, /* Not used */

    0,  /* Number of 1(5)-bit codes */
    0,  /* Number of 2(6)-bit codes */
    0,  /* Number of 3(7)-bit codes */
    0,  /* Number of 4(8)-bit codes */
    0,  /* Number of 5(9)-bit codes */
    32, /* Number of 6(10)-bit codes */
    0x0000, 11, 1,      0x0001, 11, -1,
    0x0002, 12, 1,      0x0003, 12, -1,
    0x0004, 13, 1,      0x0005, 13, -1,
    0x0006, 14, 1,      0x0007, 14, -1,
    0x0008, 5,  2,      0x0009, 5 , -2,
    0x000a, 6 , 2,      0x000b, 6 , -2,
    0x000c, 3,  3,      0x000d, 3 , -3,
    0x000e, 4 , 3,      0x000f, 4 , -3,

    0x0010, 2, 4 ,      0x0011, 2, -4 ,
    0x0012, 2, 5 ,      0x0013, 2, -5,
    0x0014, 1, 8 ,      0x0015, 1, -8 ,
    0x0016, 0, 18,      0x0017, 0, -18,
    0x0018, 0, 19,      0x0019, 0, -19,
    0x001a, 0, 20,      0x001b, 0, -20,
    0x001c, 0, 21,      0x001d, 0, -21,
    0x001e, 0, 22,      0x001f, 0, -22,
    16, /* Number of 7(11)-bit codes */
    0x0040, 5, 3,       0x0041, 5, -3,
    0x0042, 3, 4,       0x0043, 3, -4,
    0x0044, 3, 5,       0x0045, 3, -5,
    0x0046, 2, 6,       0x0047, 2, -6,
    0x0048, 1, 9,       0x0049, 1, -9,
    0x004a, 1,10,       0x004b, 1, -10,
    0x004c, 1, 11,      0x004d, 1, -11,
    0x004e, 0, 0,       0x004f, 1, 0,

    16,  /* Number of 8(12)-bit codes */
    0x00a0, 6, 3,       0x00a1, 6, -3,
    0x00a2, 4, 4,       0x00a3, 4, -4,
    0x00a4, 3, 6,       0x00a5, 3, -6,
    0x00a6, 1,12,       0x00a7, 1,-12,
    0x00a8, 1,13,       0x00a9, 1,-13,
    0x00aa, 1,14,       0x00ab, 1,-14,
    0x00ac, 2, 0,       0x00ad, 3, 0 ,
    0x00ae, 4, 0,       0x00af, 5, 0,


    16*2 + 56 + 6 + 2,  /* Number of 9(13)-bit codes */
    0x0160, 7, 2,       0x0161, 7, -2,
    0x0162, 8, 2,       0x0163, 8, -2,
    0x0164, 9, 2,       0x0165, 9, -2,
    0x0166, 10, 2,      0x0167, 10, -2,
    0x0168, 7, 3,       0x0169, 7, -3,
    0x016a, 8, 3,       0x016b, 8, -3,
    0x016c, 4, 5,       0x016d, 4, -5,
    0x016e, 3, 7,       0x016f, 3, -7,

    0x0170, 2, 7,       0x0171, 2, -7,
    0x0172, 2, 8,       0x0173, 2, -8,
    0x0174, 2, 9,       0x0175, 2, -9,
    0x0176, 2, 10,      0x0177, 2, -10,
    0x0178, 2, 11,      0x0179, 2, -11,
    0x017a, 1, 15,      0x017b, 1, -15,
    0x017c, 1, 16,      0x017d, 1, -16,
    0x017e, 1, 17,      0x017f, 1, -17,

    /*  Combinations (0,0) through (6,0) have special codes.
        They are filled to handle errors in a DV stream */
    0x0180 + 0, 0, 0,    0x0180 + 1, 0, 0,
    0x0180 + 2, 2, 0,    0x0180 + 3, 3, 0,
    0x0180 + 4, 4, 0,    0x0180 + 5, 5, 0,

    0x0180 + 6,  6,  0,         0x0180 + 7,   7, 0,         0x0180 + 8,   8, 0,         0x0180 + 9,   9, 0,/*  1 */
    0x0180 + 10, 10, 0,         0x0180 + 11, 11, 0,         0x0180 + 12, 12, 0,         0x0180 + 13, 13, 0,/*  2 */
    0x0180 + 14, 14, 0,         0x0180 + 15, 15, 0,         0x0180 + 16, 16, 0,         0x0180 + 17, 17, 0,/*  3 */
    0x0180 + 18, 18, 0,         0x0180 + 19, 19, 0,         0x0180 + 20, 20, 0,         0x0180 + 21, 21, 0,/*  4 */
    0x0180 + 22, 22, 0,         0x0180 + 23, 23, 0,         0x0180 + 24, 24, 0,         0x0180 + 25, 25, 0,/*  5 */
    0x0180 + 26, 26, 0,         0x0180 + 27, 27, 0,         0x0180 + 28, 28, 0,         0x0180 + 29, 29, 0,/*  6 */
    0x0180 + 30, 30, 0,         0x0180 + 31, 31, 0,         0x0180 + 32, 32, 0,         0x0180 + 33, 33, 0,/*  7 */
    0x0180 + 34, 34, 0,         0x0180 + 35, 35, 0,         0x0180 + 36, 36, 0,         0x0180 + 37, 37, 0,/*  8 */
    0x0180 + 38, 38, 0,         0x0180 + 39, 39, 0,         0x0180 + 40, 40, 0,         0x0180 + 41, 41, 0,/*  9 */
    0x0180 + 42, 42, 0,         0x0180 + 43, 43, 0,         0x0180 + 44, 44, 0,         0x0180 + 45, 45, 0,/* 10 */
    0x0180 + 46, 46, 0,         0x0180 + 47, 47, 0,         0x0180 + 48, 48, 0,         0x0180 + 49, 49, 0,/* 11 */
    0x0180 + 50, 50, 0,         0x0180 + 51, 51, 0,         0x0180 + 52, 52, 0,         0x0180 + 53, 53, 0,/* 12 */
    0x0180 + 54, 54, 0,         0x0180 + 55, 55, 0,         0x0180 + 56, 56, 0,         0x0180 + 57, 57, 0,/* 13 */
    0x0180 + 58, 58, 0,         0x0180 + 59, 59, 0,         0x0180 + 60, 60, 0,         0x0180 + 61, 61, 0,/* 14 (14*4=56) */

    /* We fill these codes as well to handle errors in a DV stream */
    0x0180 + 62, 62, 0,          0x0180 + 63, 63, 0,

    -1 /* end of table */
};

static Ipp32u lineTable[ ]=
{ //0, 0, 0, 0, 0, 0, 0, 1, 2,  2,  3,  3, 4, 4, 5, 5,
    5, 5, 4, 4, 3, 3, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0,
 // 0, 0, 0, 0, 1, 2, 2, 3, 3,  4,  4,  5, 5, 6, 6, 7, // V
    7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 0, 0, 0, 0,
  //0, 1, 2, 2, 3, 3, 4, 4, 5,  5,  6,  6, 7, 7, 8, 8,
    8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 0,
  //0, 0, 1, 2, 2, 3, 3, 4, 4,  5,  5,  6, 6, 7, 7, 8
 // 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 0, 0
   13, 12, 12, 8, 8, 11, 11, 6, 6, 5, 5, 4, 4, 10, 9, 9
};

Ipp32s DVVideoDecoder::DVCreateADequantizeTable()
{
    Ipp16u lpBuffer[14 *64], *lpBuffer1;
    Ipp32s i,j;

    /*  this pretty table was designed to
        avoid coincidencies with any GPL code */
    Ipp32u tabl1[] =
    {
        0,
        1,

        8,          16, 9,  2,              3,  10, 17,
        24,         32,         25,         18,         11,
        4,          5,              12,     19,             26,
        33,         40,             48,     41,             34,
        27,         20,             13,     6,              7,
        14,         21,             28,     35,             42,
        49,         56,         57,         50,         43,
        36,         29, 22, 15,             23, 30, 37,
        44,         51,                     58,
        59,         52,                     45,
        38,         31,                     39,
        46,         53,                     60,
        61,         54,                     47,
        55,         62,                     63
    };

    Ipp32u tabl2[] =
    {
        0,
        32,

        1,          33, 8,  40,             2, 34,  9,
        41,         16,         48,         24,         56,
        17,         49,             10,     42,             3,
        35,         4,              36,     11,             43,
        18,         50,             25,     57,             26,
        58,         19,             51,     12,             44,
        5,          37,         6,          38,         13,
        45,         20, 52, 27,             59, 28, 60,
        21,         53,                     14,
        46,         7,                      39,
        15,         47,                     22,
        54,         29,                     61,
        30,         62,                     23,
        55,         31,                     63
    };

    static Ipp64f TablW0[] =
    {
        (0.5/*2500076*/),(_W0*_W1/2),(_W0*_W2/2),(_W0*_W3/2),(_W0*_W4/2),(_W0*_W5/2),(_W0*_W6/2),(_W0*_W7/2),
            (_W1*_W0/2),(_W1*_W1/2),(_W1*_W2/2),(_W1*_W3/2),(_W1*_W4/2),(_W1*_W5/2),(_W1*_W6/2),(_W1*_W7/2),
            (_W2*_W0/2),(_W2*_W1/2),(_W2*_W2/2),(_W2*_W3/2),(_W2*_W4/2),(_W2*_W5/2),(_W2*_W6/2),(_W2*_W7/2),
            (_W3*_W0/2),(_W3*_W1/2),(_W3*_W2/2),(_W3*_W3/2),(_W3*_W4/2),(_W3*_W5/2),(_W3*_W6/2),(_W3*_W7/2),
            (_W4*_W0/2),(_W4*_W1/2),(_W4*_W2/2),(_W4*_W3/2),(_W4*_W4/2),(_W4*_W5/2),(_W4*_W6/2),(_W4*_W7/2),
            (_W5*_W0/2),(_W5*_W1/2),(_W5*_W2/2),(_W5*_W3/2),(_W5*_W4/2),(_W5*_W5/2),(_W5*_W6/2),(_W5*_W7/2),
            (_W6*_W0/2),(_W6*_W1/2),(_W6*_W2/2),(_W6*_W3/2),(_W6*_W4/2),(_W6*_W5/2),(_W6*_W6/2),(_W6*_W7/2),
            (_W7*_W0/2),(_W7*_W1/2),(_W7*_W2/2),(_W7*_W3/2),(_W7*_W4/2),(_W7*_W5/2),(_W7*_W6/2),(_W7*_W7/2)
    };

    static Ipp64f TablW1[] =
    {
        (0.5/*2500076*/),(_W0*_W1/2),(_W0*_W2/2),(_W0*_W3/2),(_W0*_W4/2),(_W0*_W5/2),(_W0*_W6/2),(_W0*_W7/2),
            (_W2*_W0/2),(_W2*_W1/2),(_W2*_W2/2),(_W2*_W3/2),(_W2*_W4/2),(_W2*_W5/2),(_W2*_W6/2),(_W2*_W7/2),
            (_W4*_W0/2),(_W4*_W1/2),(_W4*_W2/2),(_W4*_W3/2),(_W4*_W4/2),(_W4*_W5/2),(_W4*_W6/2),(_W4*_W7/2),
            (_W6*_W0/2),(_W6*_W1/2),(_W6*_W2/2),(_W6*_W3/2),(_W6*_W4/2),(_W6*_W5/2),(_W6*_W6/2),(_W6*_W7/2),
            (_W0*_W0/2),(_W0*_W1/2),(_W0*_W2/2),(_W0*_W3/2),(_W0*_W4/2),(_W0*_W5/2),(_W0*_W6/2),(_W0*_W7/2),
            (_W2*_W0/2),(_W2*_W1/2),(_W2*_W2/2),(_W2*_W3/2),(_W2*_W4/2),(_W2*_W5/2),(_W2*_W6/2),(_W2*_W7/2),
            (_W4*_W0/2),(_W4*_W1/2),(_W4*_W2/2),(_W4*_W3/2),(_W4*_W4/2),(_W4*_W5/2),(_W4*_W6/2),(_W4*_W7/2),
            (_W6*_W0/2),(_W6*_W1/2),(_W6*_W2/2),(_W6*_W3/2),(_W6*_W4/2),(_W6*_W5/2),(_W6*_W6/2),(_W6*_W7/2),
    };

    // clear returned pointer (may be error occurs)
    m_lpADequantizeLineTable = NULL;
    m_lpADequantizeTable     = NULL;

    // alloc aligned memory
    if( m_pMemoryAllocator->Alloc(&m_DequantizeTableMID,
                                  SIZE_TABLE_A_DEQUANTIZE * 2,
                                  UMC_ALLOC_PERSISTENT,
                                  16) != UMC_OK)
        return UMC_ERR_ALLOC;

    lpBuffer1 = (Ipp16u*)m_pMemoryAllocator->Lock(m_DequantizeTableMID);
    if(lpBuffer1 == NULL)
        return UMC_ERR_ALLOC;

    // fill adaptive dequantization values (see blue book)
    INIT_A_D_E( 0, 1, 1, 1, 1)
    INIT_A_D_E( 1, 1, 1, 1, 2)
    INIT_A_D_E( 2, 1, 1, 2, 2)
    INIT_A_D_E( 3, 1, 2, 2, 4)
    INIT_A_D_E( 4, 2, 2, 4, 4)
    INIT_A_D_E( 5, 2, 4, 4, 8)
    INIT_A_D_E( 6, 4, 4, 8, 8)
    INIT_A_D_E( 7, 4, 8, 8, 16)
    INIT_A_D_E( 8, 8, 8, 16, 16)

    INIT_A_D_E( 9, 2, 2, 2, 2)//0
    INIT_A_D_E( 10, 2, 2, 2, 4)//1
    //2- 4
    //3- 5
    //4- 6
    INIT_A_D_E( 11, 4, 8, 8, 16)//5
    //6- 8
    INIT_A_D_E( 12, 8, 16, 16, 32)//7
    INIT_A_D_E( 13, 16, 16, 32, 32)//8

#ifdef FAST_DV
    for(j=0;j<14;j++)
        for(i=0;i<64;i++)
            lpBuffer1[j * 64 + tabl1[i]] = (Ipp16u) (lpBuffer[j* 64 + i] * (Ipp32s)(((Ipp64f) (1 << 8)) /  TablW0[tabl1[i]]));

        for( j=0;j<14;j++)
            for(i=0;i<64;i++)
                lpBuffer1[64 * 14 + j * 64 + tabl2[i]] = (Ipp16u) (lpBuffer[j* 64 + i]*(Ipp32s)(((Ipp64f) (1 << 8 )) / TablW1[tabl2[i]]));
#else
     for(j=0;j<14;j++)
        for(i=0;i<64;i++)
            lpBuffer1[j * 64 + tabl1[i]] = (Ipp16u) (lpBuffer[j* 64 + i]);// * (Ipp32s)(((Ipp64f) (1 << 8)) /  TablW0[tabl1[i]]));

        for( j=0;j<14;j++)
            for(i=0;i<64;i++)
                lpBuffer1[64 * 14 + j * 64 + tabl2[i]] = (Ipp16u) (lpBuffer[j* 64 + i]);//*(Ipp32s)(((Ipp64f) (1 << 8 )) / TablW1[tabl2[i]]));
#endif


    m_pMemoryAllocator->Unlock(m_DequantizeTableMID);

    m_lpADequantizeLineTable = lineTable;

    return 0;

} //Ipp32s DVCreateADequantizeTable(Ipp32u **m_lpADequantizeTable)

/*  this pretty table was designed to
    avoid coincidences with any GPL code */
Ipp32u DVVideoDecoder::_INTERNAL_DEZIGZAG_TABLE_0[] =
{
    0,
    1,

    8,          16, 9,  2,              3, 10,  17,
    24,         32,         25,         18,         11,
    4,          5,              12,     19,             26,
    33,         40,             48,     41,             34,
    27,         20,             13,     6,              7,
    14,         21,             28,     35,             42,
    49,         56,         57,         50,         43,
    36,         29, 22, 15,             23, 30, 37,
    44,         51,                     58,
    59,         52,                     45,
    38,         31,                     39,
    46,         53,                     60,
    61,         54,                     47,
    55,         62,                     63,

    0,  32,  1, 33,  8, 40,  2, 34,
    9,  41, 16, 48, 24, 56, 17, 49,
    10, 42,  3, 35,  4, 36, 11, 43,
    18, 50, 25, 57, 26, 58, 19, 51,
    12, 44,  5, 37,  6, 38, 13, 45,
    20, 52, 27, 59, 28, 60, 21, 53,
    14, 46,  7, 39, 15, 47, 22, 54,
    29, 61, 30, 62, 23, 55, 31, 63
};

#undef INIT_A_D_E
#undef SIZE_TABLE_A_DEQUANTIZE

#undef _INTERNAL_CS1
#undef _INTERNAL_CS2
#undef _INTERNAL_CS3
#undef _INTERNAL_CS4
#undef _INTERNAL_CS5
#undef _INTERNAL_CS6
#undef _INTERNAL_CS7

#undef _W0
#undef _W1
#undef _W2
#undef _W3
#undef _W4
#undef _W5
#undef _W6
#undef _W7

} // end namespace UMC

#endif //(UMC_ENABLE_DV_VIDEO_DECODER)
